#ifndef INPUT_H
#define INPUT_H

/*	CLASS:		Input.h
	AUTHOR:		Marcelo Y. B. Hossomi
	
	General file reader. Able to skip line comments, delimited
	comments and separators.

	Tags:
	
		tags[0]			Full line comment		(default: #)
		tags[1]			Comment start			(default: <)
		tags[2]			Comment end				(default: >)
		tags[3+]		Separators				(default: ,)

	NOTE: first three tags are mandatory. If insufficient tags
	are given, default will be used.
*/

#include <iostream>
#include <fstream>
#include <iomanip>
#include <cstring>
#include "Exception.h"
#include "NotReady.h"
#include "NotFound.h"
#include "EndOfFile.h"
using namespace std;

class Input {
private:

	ifstream	file;	// Input file.
	char		*tags;	// Tags used for comments and separators.
	int			ntags;	// Number of tags used.
	bool		ready;	// 'true' if successfully opened.
	bool		end;	// 'true' if has reached end of file.

	// Skip comments and separators.
	void skip() throw (NotReady, EndOfFile);
	void postSkip() throw (NotReady);
	
public:

	Input();
	Input( const char *file )					throw (NotFound);
	Input( const char *file, const char *tags )	throw (NotFound);
	~Input();

	// Control.

	void open( const char *file )	throw (NotFound);
	void close()					throw (NotReady);
	bool finished()					throw (NotReady);
	bool hasFinished()				{ return end; }
	bool isReady()					{ return ready; }

	// Read data.

	void read( char *x )			throw (NotReady);
	void read( char &x )			throw (NotReady);
	void read( int &x )				throw (NotReady);
	void read( double &x )			throw (NotReady);
	void read( double *v, int n )	throw (NotReady);
	void read( int *v, int n )		throw (NotReady);
	void read( double **v, int n, int m )	throw (NotReady);
	void read( int **v, int n, int m )		throw (NotReady);

};

#endif